package org.redis.cluster.util;

import java.util.Collection;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

public class Assert {
	
	public static void mustNumber(String value,String message,String...parameters) {
		isTrue(StringUtils.isNumeric(value),message,parameters);
	}
	
	public static void mustNumber(String value) {
		mustNumber(value,null);
	}
	
	public static void notEmpty(Collection<?> value,String message,String...parameters) {
		isTrue(CollectionUtils.isNotEmpty(value),message,parameters);
	}

	public static void notEmpty(Collection<?> value) {
		notEmpty(value,null);
	}
	
	public static void hasLength(String value,String message,String...parameters) {
		isTrue(StringUtils.isNotBlank(value),message,parameters);
	}
	
	public static void hasLength(String value) {
		hasLength(value,null);
	}
	
	public static void notNull(Object value,String message,String...parameters) {
		isTrue(value!=null,message,parameters);
	}

	public static void notNull(Object value) {
		notNull(value,null);
	}

	public static void isTrue(boolean value,String message,String...parameters) {
		if(value) {
			return;
		}
		
		throwException(message,parameters);
	}
	
	public static void isTrue(boolean value) {
		isTrue(value,null);
	}
	
	protected static void throwException(String message,String...parameters) {
		if(StringUtils.isNotBlank(message)) {
			throw new IllegalArgumentException(String.format(message, parameters));
		}
		else {
			throw new IllegalArgumentException();
		}
	}
}